package org.summer.gateway.repoistory;

import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.summer.gateway.pojo.SecurityPath;
import reactor.core.publisher.Flux;

@Repository
public interface SecurityPathRepository extends R2dbcRepository<SecurityPath,Long> {
    /**
     * 根据角色编号查找角色可以请求的路径集合
     * @param roleId 角色编号
     */
    @Query("""
    SELECT p.id as id,pattern,method
    FROM security_path p
             LEFT JOIN security_role_path rp
                       ON p.id = rp.path_id AND rp.`delete`=FALSE AND p.`delete`=FALSE
    WHERE rp.role_id=:roleId
    """)
    Flux<SecurityPath> selectListByRoleId(@Param("roleId") Long roleId);
}
